<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>2345网咖 - 用户中心</title>
    <style type="text/css">
        body {
            background-image: url('https://img.zcool.cn/community/0116bb5d4bcb2ca80120695cdaa257.jpg@1280w_1l_2o_100sh.jpg');
            background-size: cover;
            background-repeat: no-repeat;
            font-family: Arial, sans-serif;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            background-color: rgba(217, 212, 212, 0.5); /* 半透明背景色 */
            border-radius: 10px;
            text-align: center;
            color: white; /* 设置文本颜色为白色 */
        }
        .navbar {
            overflow: hidden;
            background-color: rgba(0, 0, 0, 0.7);
            padding: 10px;
        }
        .navbar a {
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 14px 16px;
            text-decoration: none;
        }
        .navbar a:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }
        h1 {
            margin-top: 0;
        }
        .user-info {
            margin-bottom: 20px;
        }
        .logout-button {
            text-align: center;
        }
    </style>
</head>
<body>

<div class="navbar">
    <a href="User%20Center.jsp.">首页</a>
    <a href="shopping.jsp">购买商品</a>
    <a href="profile.html">个人资料</a>
    <a href="settings.html">设置</a>
</div>

<div class="container">
    <h1>2345网咖 - 用户中心</h1>
    <div class="user-info">
        <p>欢迎, <span id="username">User</span>!</p>
        <p>当前时间: <span id="currentTime"></span></p>
        <p>上机时间: <span id="onlineTime"></span></p>
    </div>
    <div class="logout-button">
        <button onclick="logout()">下机</button>
    </div>
</div>

<script type="text/javascript">
    //<![CDATA[
    function logout() {
        // 清除本地存储的用户信息
        localStorage.removeItem("username");
        localStorage.removeItem("password");
        // 跳转到登录页面
        window.location.href = "over.jsp";
    }

    // 显示当前时间
    function showCurrentTime() {
        var currentTime = new Date();
        document.getElementById("currentTime").textContent = currentTime.toLocaleString();
    }

    // 显示上机时间
    function showOnlineTime() {
        var onlineTime = new Date();
        var timeDiff = onlineTime.getTime() - startTime.getTime();
        var hours = Math.floor(timeDiff / (1000 * 60 * 60));
        var minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
        document.getElementById("onlineTime").textContent = hours + "小时 " + minutes + "分钟 " + seconds + "秒";
    }

    // 页面加载时显示当前时间
    var startTime = new Date();
    window.onload = function() {
        showCurrentTime();
        // 每秒更新一次时间
        setInterval(showCurrentTime, 1000);
        // 每秒更新一次上机时间
        setInterval(showOnlineTime, 1000);
    };
    //]]>
</script>
</body>
</html>
